//
//  AlertWishView.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/11/11.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "AlertWishView.h"

@implementation AlertWishView
@synthesize showView,
shopImage,
avatar,
cancleBtn,
prayInfoattr,
prayInfo,
createTime,
alphaView,
nickName;
-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        //        self.backgroundColor=[UIColor blackColor];
        //        self.alpha=0.8;
        
        [self creatUI];
    }
    return self;
}
-(void)creatUI{
    
    UITapGestureRecognizer* singleRecognizer;
    singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancleShareClick)];
    //点击的次数
    singleRecognizer.numberOfTapsRequired = 1; // 单击
    UITapGestureRecognizer* singleRecognizer2;
    singleRecognizer2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shopShareClick)];
    //点击的次数
    singleRecognizer2.numberOfTapsRequired = 1; // 单击
    //透明视图
    alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64)];
    alphaView.backgroundColor=[UIColor blackColor];
    alphaView.alpha=0.3;
    [self addSubview:alphaView];
    
    showView=[[UIView alloc]initWithFrame:CGRectMake(MainW/2-25, MainH/2-25, 50, 50)];
    showView.backgroundColor=[UIColor whiteColor];
    ViewRadius(showView, 3);
    [self addSubview:showView];
    

    [UIView animateWithDuration:0.3 animations:^{
        showView.frame=CGRectMake(MainW/2-125, MainH/2-150, 250, 200);
    }completion:^(BOOL finished) {
        NSString*string=[NSString stringWithFormat:@"%@",self.shareDic[@"imageUrl"]];
        shopImage=[[UIImageView alloc]initWithFrame:CGRectMake(95, 14, 60, 60)];
        [shopImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.shareDic[@"imageUrl"]]]];
        self.shopImage.userInteractionEnabled=YES;
        [self.shopImage addGestureRecognizer:singleRecognizer2];
        [showView addSubview:shopImage];
        
        prayInfoattr=[[UILabel alloc]initWithFrame:CGRectMake(20, shopImage.bsg_bottom+10, showView.frame.size.width-40, 20)];
        prayInfoattr.text=@"求财";
        NSMutableArray*array=[NSMutableArray array];
        for (NSDictionary*dic in self.shareDic[@"prayInfoattr"]) {
            [array addObject:dic[@"name"]];
        }
        prayInfoattr.text=[array componentsJoinedByString:@" "];
        //prayInfoattr.text=[NSString stringWithFormat:@"%@",self.shareDic[@"prayInfoattr"]];
        prayInfoattr.textColor=Red_Color;
        //titleLable.backgroundColor=TextColor3;
        prayInfoattr.font=[UIFont systemFontOfSize:14];
        prayInfoattr.textAlignment=1;
        [showView addSubview:prayInfoattr];
        if ([string isEqualToString:@"<null>"]) {
             prayInfoattr.frame=CGRectMake(10, 15, showView.frame.size.width-20, 30);
            shopImage.hidden=YES;
        }
        
        prayInfo=[[UILabel alloc]initWithFrame:CGRectMake(10, prayInfoattr.bsg_bottom+10, showView.frame.size.width-20, 20)];
       
        //self.shareLable.text=@"分享价:666";
        prayInfo.textColor=TextColor6;
        //prayInfo.backgroundColor=[UIColor greenColor];
        prayInfo.font=[UIFont systemFontOfSize:14];
        prayInfo.textAlignment=1;
        prayInfo.text=[NSString stringWithFormat:@"%@",self.shareDic[@"prayInfo"]];
        prayInfo.font = FontAndStyle14;
        prayInfo.numberOfLines = 0;
        [prayInfo sizeToFit];
        CGFloat height = prayInfo.frame.size.height;
        prayInfo.frame=CGRectMake(showView.frame.size.width/2-prayInfo.frame.size.width/2,prayInfoattr.bsg_bottom+10 , prayInfo.frame.size.width, height);
        [showView addSubview:prayInfo];
        
        createTime=[[UILabel alloc]initWithFrame:CGRectMake(10, prayInfo.bsg_bottom+10, showView.frame.size.width-30, 15)];
        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
        formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        
        // 毫秒值转化为秒
        NSDate* date = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",self.shareDic[@"createTime"]] doubleValue]/ 1000.0];
        NSString* dateString = [formatter stringFromDate:date];
        createTime.text=dateString;
        createTime.textColor=TextColor9;
        //titleLable.backgroundColor=TextColor3;
        createTime.font=[UIFont systemFontOfSize:12];
        createTime.textAlignment=2;
        CGSize size=[createTime.text sizeWithAttributes:@{NSFontAttributeName:createTime.font }];
        [showView addSubview:createTime];
        createTime.frame=CGRectMake(showView.bsg_width-size.width-20, prayInfo.bsg_bottom+10, size.width, 20);
        
        
        avatar=[[UIImageView alloc]initWithFrame:CGRectMake(createTime.bsg_right-size.width,createTime.bsg_bottom+5 , 20, 20)];
        [avatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.shareDic[@"avatar"]]]];;
        [showView addSubview:avatar];
        ViewRadius(avatar, 10);
        showView.bsg_height=CGRectGetMaxY(avatar.frame)+20;
        nickName=[[UILabel alloc]initWithFrame:CGRectMake(avatar.bsg_right+5, createTime.bsg_bottom+5, showView.frame.size.width-avatar.bsg_right-10, 20)];
        nickName.text=self.shareDic[@"nickName"];
        nickName.textColor=TextColor9;
        //titleLable.backgroundColor=TextColor3;
        nickName.font=[UIFont systemFontOfSize:12];
        [showView addSubview:nickName];
        
        
        
        cancleBtn=[[UIButton alloc]initWithFrame:CGRectMake(showView.frame.size.width-20, 0, 20, 20)];
        [cancleBtn setBackgroundImage:[UIImage imageNamed:@"icon_close"] forState:0];
//        cancleBtn.titleLabel.font=[UIFont systemFontOfSize:14];
//        [cancleBtn setTitleColor:[UIColor redColor] forState:0];
        //[cancleBtn setBackgroundColor:[UIColor cyanColor]];
        [cancleBtn addTarget:self action:@selector(cancleShareClick) forControlEvents:UIControlEventTouchUpInside];
        [showView addSubview:cancleBtn];
        
        
       
    }] ;
    
    [alphaView addGestureRecognizer:singleRecognizer];
    
}
-(void)cancleShareClick{
    if ([_delegate respondsToSelector:@selector(cancleClickShare)]) {
        [_delegate cancleClickShare];
    }
    
}
-(void)shopShareClick{
    if ([_delegate respondsToSelector:@selector(shopClickDetail)]) {
        [_delegate shopClickDetail];
    }
}
@end
